package com.ruoyi.mes.service.impl;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.List;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.mes.utils.CodeUtils;
import org.apache.poi.ss.usermodel.DateUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.mes.mapper.ProDesignMapper;
import com.ruoyi.mes.domain.ProDesign;
import com.ruoyi.mes.service.IProDesignService;

/**
 * 产品设计Service业务层处理
 * 
 * @author CFL
 * @date 2024-04-28
 */
@Service
public class ProDesignServiceImpl implements IProDesignService 
{
    @Autowired
    private ProDesignMapper proDesignMapper;

    /**
     * 查询产品设计
     * 
     * @param id 产品设计主键
     * @return 产品设计
     */
    @Override
    public ProDesign selectProDesignById(Long id)
    {
        return proDesignMapper.selectProDesignById(id);
    }

    /**
     * 查询产品设计列表
     * 
     * @param proDesign 产品设计
     * @return 产品设计
     */
    @Override
    public List<ProDesign> selectProDesignList(ProDesign proDesign)
    {
        return proDesignMapper.selectProDesignList(proDesign);
    }

    /**
     * 新增产品设计
     * 
     * @param proDesign 产品设计
     * @return 结果
     */
    @Override
    public int insertProDesign(ProDesign proDesign)
    {
        BaseController baseController = new BaseController();
        String username = baseController.getUsername();
        // 产品编码
        String proSn = CodeUtils.ProCodeCreat();
        // 设置创建者和创建时间
        proDesign.setCreatedBy(username);
        proDesign.setCreatedTime(DateUtils.getNowDate());
        proDesign.setProSn(proSn);
        return proDesignMapper.insertProDesign(proDesign);
    }

    /**
     * 修改产品设计
     * 
     * @param proDesign 产品设计
     * @return 结果
     */
    @Override
    public int updateProDesign(ProDesign proDesign)
    {
        BaseController baseController = new BaseController();
        String username = baseController.getUsername();
        proDesign.setUpdatedBy(username);
        proDesign.setUpdatedDate(DateUtils.getNowDate());
        return proDesignMapper.updateProDesign(proDesign);
    }

    /**
     * 批量删除产品设计
     * 
     * @param ids 需要删除的产品设计主键
     * @return 结果
     */
    @Override
    public int deleteProDesignByIds(Long[] ids)
    {
        return proDesignMapper.deleteProDesignByIds(ids);
    }

    /**
     * 删除产品设计信息
     * 
     * @param id 产品设计主键
     * @return 结果
     */
    @Override
    public int deleteProDesignById(Long id)
    {
        return proDesignMapper.deleteProDesignById(id);
    }
}
